﻿using System;
using System.Collections.Generic;
using System.Linq;
using EncuentraloSilverlight.Models;

namespace EncuentraloSilverlight.Web.Models
{
    public partial class Address
    {
        public bool IsValid
        {
            get { return (GetAdressRuleViolations().Count() == 0); }
        }

        public IEnumerable<RuleViolation> GetAdressRuleViolations()
        {
            if(String.IsNullOrWhiteSpace(City))
                yield return new RuleViolation("City name required", "City");
            if(String.IsNullOrWhiteSpace(Commune))
                yield return new RuleViolation("Commune name required", "Commune");
            if(User!=null && Seller!=null)
                yield return new RuleViolation("User or Seller must be null", "UserSeller");
            if(String.IsNullOrWhiteSpace(Street))
                yield return new RuleViolation("Street name required", "Street");
            if (String.IsNullOrWhiteSpace(Number))
                yield return new RuleViolation("Adress number required", "Number");

            yield break;
        }
    }
}